<extend name="Layout/ins_popup" />
<block name="content">
	<div class="popup-frame">
		<input type="hidden" name="val" id="val">
		<input type="hidden" name="name" id="name">
		<div class="popup-header ">
			<div class="pull-left">
				<h1>请选择上级部门</h1>
			</div>
			<div class="pull-right">
				<a id="save" class="btn">确定</a>
				<a id='close' class="btn btn-cancel">关闭</a>
			</div>
		</div>
		<div class="popup-body">
			<div class="popup-body-scroll">
				<div class="popup-content">
					<div class="popup_tree_menu">
						<ul class="tree_menu">
							<li>
								<a node="0"><i class="fa fa-angle-right"></i> <span>根节点</span> </a>
								{$menu}
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		var index = parent.layer.getFrameIndex(window.name);
		layui.use(['global'], function() {
			var $ = layui.jquery;
			

			parent_node = $(".sub-sidebar ul.tree_menu a.active", parent.document).attr("node");
			console.log(parent_node);
			$("ul.tree_menu a[node='" + parent_node + "']").addClass("disabled");
			$(".popup_tree_menu a:not('.disabled')").click(function() {
				$("#val").val($(this).attr("node"));
				$("#name").val($(this).children("span").text());
				$(".tree_menu a.active").removeClass("active");
				$(this).addClass("active");
			});

			//保存后关闭
			$('#save').on('click', function() {
				if ($("#name").val().length > 0) {
					$("#dept_name", parent.document).val($("#name").val());
					$("#pid", parent.document).val($("#val").val());
				} else {
					parent.layer.msg('"请选择级部门"');
					return false;
				}
				parent.layer.close(index);
				//parent.layer.msg('新建成功');
			});
			//关闭iframe
			$('#close').click(function() {
				parent.layer.close(index);
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:U('winpop')}", 560, 470);
			});

		});
	</script>
</block>